//
//  LookDetailsTeamCell.m
//  Doctor1.0
//
//  Created by mk on 15/11/13.
//  Copyright (c) 2015年 cocoa-mk. All rights reserved.
//

#import "LookDetailsTeamCell.h"

@implementation LookDetailsTeamCell

- (void)awakeFromNib
{
    // Initialization code
    
    imageDoctorAvatay.layer.masksToBounds = YES;
    imageDoctorAvatay.layer.cornerRadius = imageDoctorAvatay.width/2.0f;
    btnLookTeam.layer.masksToBounds = YES;
    btnLookTeam.layer.cornerRadius = 4;
    btnLookTeam.hidden = YES;
    
    for (NSLayoutConstraint *constraints in [labHonor constraints])
    {
        if (constraints.firstItem == labHonor && constraints.firstAttribute == NSLayoutAttributeWidth)
        {
            constraints.constant = (appScreenWidth-20);
            break;
        }
    }
    
    for (NSLayoutConstraint *constraints in [self.labDesc constraints])
    {
        if (constraints.firstItem == self.labDesc && constraints.firstAttribute == NSLayoutAttributeWidth)
        {
            constraints.constant = (appScreenWidth-36);
            break;
        }
    }

}


-(void)fillDataWith:(NSMutableDictionary *)dic showMoreDesc:(BOOL)show
{
    //团队
    for (NSLayoutConstraint *constraints in [viewTeamData constraints])
    {
        if (constraints.firstItem == viewTeamData && constraints.firstAttribute == NSLayoutAttributeHeight)
        {
            [viewTeamData removeConstraint:constraints];
            break;
        }
    }
    for (NSLayoutConstraint *constraints in [viewDesc constraints])
    {
        if (constraints.firstItem == viewDesc && constraints.firstAttribute == NSLayoutAttributeHeight)
        {
            [viewDesc removeConstraint:constraints];
            break;
        }
    }
    
    
    if (dic.allKeys.count > 0)
    {
        [imageDoctorAvatay sd_setImageWithURL:NullObjToString([dic objectForKey:@"imageUrl"]) placeholderImage:loadDoctorImageDefaule];//医生头像
        
        labTitle.text = [NSString stringWithFormat:@"%@/%@",NullObjToString([dic objectForKey:@"mTitle"]),NullObjToString([dic objectForKey:@"aTitle"])];//职称
        labHospital.text = NullObjToString([dic objectForKey:@"hospital"]);//医院
    
        //荣誉
        id honour = [dic objectForKey:@"honour"];
        if([honour isKindOfClass:[NSArray class]] && [honour allObjects].count>0)
        {
            NSMutableArray * arrHonour = [[NSMutableArray alloc]initWithCapacity:0];
            [arrHonour addObjectsFromArray:honour];
            NSString * strHonour = @"";
            for (int i = 0; i<arrHonour.count; i++)
            {
                if([strHonour isEqualToString:@""]) strHonour = [NSString stringWithFormat:@"%d.%@",i+1,[arrHonour objectAtIndex:i]];
                else strHonour = [NSString stringWithFormat:@"%@\n%d.%@",strHonour,i+1,[arrHonour objectAtIndex:i]];
            }
            labHonor.text = strHonour;//荣誉
        }
         btnLookTeam.hidden = NO;
    }else
    {
        //view2.h = 0
        NSLayoutConstraint * layout =  [NSLayoutConstraint constraintWithItem:viewTeamData
                                                                    attribute:NSLayoutAttributeHeight
                                                                    relatedBy:NSLayoutRelationEqual
                                                                       toItem:nil
                                                                    attribute:NSLayoutAttributeHeight
                                                                   multiplier:1.0f
                                                                     constant:0];
        layout.priority = 1000;
        [viewTeamData addConstraint:layout];
        
    }
    
    if(self.labDesc.text.length == 0)
    {
        NSLayoutConstraint * layout =  [NSLayoutConstraint constraintWithItem:viewDesc
            attribute:NSLayoutAttributeHeight
            relatedBy:NSLayoutRelationEqual
            toItem:nil
            attribute:NSLayoutAttributeHeight
            multiplier:1.0f
            constant:0];
            layout.priority = 1000;
            [viewDesc addConstraint:layout];
    }else
    {
        CGSize sizeMax = [self.labDesc.text boundingRectWithSize:CGSizeMake((appScreenWidth-36),1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
        
       CGSize sizeMin = [self.labDesc.text boundingRectWithSize:CGSizeMake((appScreenWidth-36),(17*5)) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
        
        CGFloat h = (show?sizeMax.height+30:sizeMin.height+30);
       // NSLog(@"=最小高度==%f===最大高度==%f====view高度:=%f",sizeMin.height,sizeMax.height,h);
        
        if (sizeMin.height == sizeMax.height)
        {
            imageMore.hidden = YES;
            btnMore.hidden = YES;
        }else
            
        {
            imageMore.hidden = NO;
            btnMore.hidden = NO;
        }
    
        NSLayoutConstraint * layout =  [NSLayoutConstraint constraintWithItem:viewDesc
                attribute:NSLayoutAttributeHeight
                relatedBy:NSLayoutRelationEqual
                toItem:nil
                attribute:NSLayoutAttributeHeight
                multiplier:1.0f
                constant:h];
        layout.priority = 1000;
        [viewDesc addConstraint:layout];

    }
}


#pragma mark 查看团队
-(IBAction)clickLookTeam:(id)sender
{
    
    if ([self.celldelegate respondsToSelector:@selector(clickLookTeamWithCell:)])
    {
        [self.celldelegate clickLookTeamWithCell:self];
    }
}

#pragma mark 查看更多疾病
-(IBAction)btnLookMoreDesc:(id)sender
{
    if ([self.celldelegate respondsToSelector:@selector(btnLookMoreDescWithCell:)])
    {
        [self.celldelegate btnLookMoreDescWithCell:self];
    }
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end





